package com.shtel.bss.saas.core.base.spring;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author xiezhiwei
 * @version Revision 1.0
 * @版权： 版权所有 (c) 2018
 * @创建日期： 2020/2/4 13:58
 * @功能说明：
 */
@Component("defaultApplicationContextUtil")
@Lazy(false)
@Order(0)
public class ApplicationContextUtil implements ApplicationContextAware {

	private static ApplicationContext context;

	public ApplicationContextUtil() {
	}

	public void setApplicationContext(ApplicationContext contex) {
		context = contex;
	}

	public static ApplicationContext getContext() {
		return context;
	}

	public static <T> T getBean(String beanId) {
		return (T) context.getBean(beanId);
	}

	public static boolean containsBean(String beanId) {
		return context.containsBean(beanId);
	}

	public static <T> T getBean(String beanId, Object... args) {
		return (T) context.getBean(beanId, args);
	}

	public static <T> T getBean(Class<T> clazz) {
		return context.getBean(clazz);
	}
}
